/**
 * 宽带预约详情
 */
(function($){
  /*
  显示数据
  */
  var showDatas = function(data){
  	var $tpl = $('#amz-tpl');
    var source = $tpl.text();
    var template = Handlebars.compile(source);
    var myData = {
    	broadband: data,
    	"error":"没有宽带详情信息"
    };

    var html = template(myData);
    $tpl.before(html);
  };
  /*
  加载数据
  */
  var loadDatas = function(){
  	$('#modal').modal('open');
  	var params = {"id":getParamValue("id")};
  	$.ajax({
	    type: "post",
	    url: "../broadbandH5/detail",
	    data: params,
	    dataType: "json",
	    headers: {
      'token': getParamValue('token'),
      'saleType': getParamValue('saleType')
    },
    success: function(data) {
      if (data.ResultCode === 1009) {
        alert('登陆超时，请重新登录！');
        jumpToSignin();
        return;
      }
	    	$('#modal').modal('close');
	       console.info(data);
	       showDatas(data);
	    },
	    error : function(textStatus) {
	    	$('#modal').modal('close');
	        alert("获取宽带详情信息失败！");
	        console.info("request error");
	    }
	  });
  };
  /*
  绑定事件
  */
  var bindEvent = function(){
    $("#broadband-reservation-btn").on("click",function(){
      var params = "?";
      var myParam = getParams();
      if(myParam){
        params += myParam;
      }
      window.location.href = "broadband_reservation_new.html" + params;
    });
  };

  $(function(){
    bindEvent();
    /*获取参数*/
    $("#broadband-id").val(getParamValue("id"));
    $("#broadband-name").html(decodeURIComponent(getParamValue("name")));

    /*加载模态窗口*/
  	var options = {
  		closeViaDimmer: false
  	};
    $('#modal').modal(options);

    loadDatas();
  });
})(jQuery);
